Options:
-h, --help Print this message
-j N, --jobs N The number of jobs to run in parallel
+ --release Build artifacts in release mode, with optimizations
+ --target TRIPLE Build for the target triple
-u, --update-remotes Deprecated option, use `cargo update` instead
--manifest-path PATH Path to the manifest to execute
-v, --verbose Use verbose output
let mut compile_opts = ops::CompileOptions {
update: options.flag_update_remotes,
- env: "compile",
+ env: if options.flag_release { "release" } else { "compile" },
shell: shell,
jobs: options.flag_jobs,
- target: None,
+ target: options.flag_target.as_ref().map(|t| t.as_slice()),
dev_deps: true,
};
let root = try!(src.get_root_package());
let compile = try!(ops::compile(manifest_path, options));
- let exe = manifest_path.dir_path().join("target").join(root.get_name());
+ let mut exe = manifest_path.dir_path().join("target");
+ if options.env == "release" {
+ exe = exe.join("release");
+ }
+ let exe = exe.join(root.get_name());
let exe = match exe.path_relative_from(&os::getcwd()) {
Some(path) => path,
None => exe,
self.build_dir().join(format!("{}{}", b, os::consts::EXE_SUFFIX))
}
+ pub fn release_bin(&self, b: &str) -> Path {
+ self.build_dir().join("release").join(format!("{}{}", b, os::consts::EXE_SUFFIX))
+ }
+
pub fn target_bin(&self, target: &str, b: &str) -> Path {
self.build_dir().join(target).join(format!("{}{}", b,
os::consts::EXE_SUFFIX))
", compiling = COMPILING, running = RUNNING, foo = p.url(), triple = target,
doctest = DOCTEST)));
})
+
+test!(simple_cargo_run {
+ if disabled() { return }
+
+ let target = alternate();
+
+ let build = project("builder")
+ .file("Cargo.toml", r#"
+ [project]
+ name = "foo"
+ version = "0.5.0"
+ authors = ["wycats@example.com"]
+ "#)
+ .file("src/main.rs", format!(r#"
+ fn main() {{
+ assert_eq!(std::os::getenv("TARGET").unwrap().as_slice(), "{}");
+ }}
+ "#, target).as_slice());
+ assert_that(build.cargo_process("cargo-run").arg("--target").arg(target),
+ execs().with_status(0));
+
+ let p = project("foo")
+ .file("Cargo.toml", format!(r#"
+ [package]
+ name = "foo"
+ version = "0.0.0"
+ authors = []
+ build = '{}'
+ "#, build.bin("foo").display()))
+ .file("src/main.rs", r#"
+ use std::os;
+ fn main() {
+ assert_eq!(os::consts::ARCH, "x86");
+ }
+ "#);
+
+ let target = alternate();
+ assert_that(p.cargo_process("cargo-run").arg("--target").arg(target),
+ execs().with_status(0));
+})
assert_that(p.cargo_process("cargo-run").arg("hello").arg("world"),
execs().with_status(0));
})
+
+test!(release_works {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [project]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+ "#)
+ .file("src/main.rs", r#"
+ fn main() { if !cfg!(ndebug) { fail!() } }
+ "#);
+
+ assert_that(p.cargo_process("cargo-run").arg("--release"),
+ execs().with_status(0).with_stdout(format!("\
+{compiling} foo v0.0.1 ({dir})
+{running} `target{sep}release{sep}foo`
+",
+ compiling = COMPILING,
+ running = RUNNING,
+ dir = path2url(p.root()),
+ sep = path::SEP).as_slice()));
+ assert_that(&p.release_bin("foo"), existing_file());
+})